﻿using Checkbox.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Checkbox.Controllers
{
    public class ProductController : Controller
    {
        // GET: Product

        private Model1 db = new Model1();

        [HttpGet]
        public ActionResult Index()
        {
            ViewBag.ListProduct = db.Products.ToList();
            return View();
        }
        [HttpPost]
        public ActionResult Index (FormCollection formCollection)
        {
            string[] ids = formCollection["productId"].Split(new char[] { ',' });
            foreach(string id in ids)
            {
                var product = db.Products.Find(int.Parse(id));
                db.Products.Remove(product);
                db.SaveChanges();
            }
            return RedirectToAction("Index");
        }
    }
}